package visitor;

import java.lang.reflect.InvocationTargetException;

import javax.management.RuntimeErrorException;

import syntaxtree.AbstractNode;


public final class VisitorUtil {

	private VisitorUtil() {
	}

	public static Object visit(Object visitor, AbstractNode n) {
		Exception exception;
		try {
			return visitor.getClass().getMethod("visit", n.getClass()).invoke(visitor, n);
		} catch (IllegalAccessException e) {
			exception = e;
		} catch (InvocationTargetException e) {
			exception = e;
		} catch (NoSuchMethodException e) {
			exception = e;
		}
		throw new RuntimeErrorException(new Error(exception));
	}
}
